﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.UI;
using TableTools;
using TableTools.Designer;

namespace HYRElectric.LightningCalculation
{
	public class GridDrawingKit
	{
		public GridDrawingKit(CalculationData calculateData)
		{
			this.m_CalculateData = calculateData;
		}

		public bool DrawingGrid(ExternalCommandData cmdData)
		{
			int rowCount = 0;
			int colCount = 0;
			List<CellInfo> cellInfos;
			if (this.m_CalculateData.IsFormulaMethod)
			{
				cellInfos = this.GetAllCellInfoByFormaulaMethod(ref rowCount, ref colCount);
			}
			else
			{
				cellInfos = this.GetFAllCellInfoByGraphicMethod(ref rowCount, ref colCount);
			}
			string text = "";
			TableInterface.DrawGeneralTable(cmdData, rowCount, colCount, cellInfos, ref text, null, null, true);
			return true;
		}

		private List<CellInfo> GetAllCellInfoByFormaulaMethod(ref int rowCount, ref int colCount)
		{
			List<CellInfo> list = new List<CellInfo>();
			rowCount = 9;
			colCount = 3;
			list.Add(new CellInfo(0, 4, 0, 0, "建筑物数据", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(5, 6, 0, 0, "气象参数", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(7, 8, 0, 0, "计算结果", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 1, 1, "建筑物数长度L(m)", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(1, 1, 1, 1, "建筑物数宽度W(m)", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(2, 2, 1, 1, "建筑物数高度H(m)", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(3, 3, 1, 1, "等效面积Ae(km2)", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(4, 4, 1, 1, "建筑物属性", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(5, 5, 1, 1, "年平均雷暴日Td(d/a)", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(6, 6, 1, 1, "年平均密度Ng(次/(km2.a))", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(7, 7, 1, 1, "预计雷击次数N(次/a)", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(8, 8, 1, 1, "防雷类别", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 2, 2, this.m_CalculateData.BuildingLength.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(1, 1, 2, 2, this.m_CalculateData.BuildingWidth.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(2, 2, 2, 2, this.m_CalculateData.BuildingHeight.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(3, 3, 2, 2, this.m_CalculateData.Ae.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(4, 4, 2, 2, this.m_CalculateData.BuildingParamter, CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(5, 5, 2, 2, this.m_CalculateData.Td.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(6, 6, 2, 2, this.m_CalculateData.Ng.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(7, 7, 2, 2, this.m_CalculateData.N.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(8, 8, 2, 2, this.m_CalculateData.ProtectionCategory, CellInfo.CellInfoType.CIT_Text));
			return list;
		}

		private List<CellInfo> GetFAllCellInfoByGraphicMethod(ref int rowCount, ref int colCount)
		{
			List<CellInfo> list = new List<CellInfo>();
			rowCount = 6;
			colCount = 3;
			list.Add(new CellInfo(0, 1, 0, 0, "建筑物数据", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(2, 3, 0, 0, "气象参数", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(4, 5, 0, 0, "计算结果", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 1, 1, "等效面积Ae(km2)", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(1, 1, 1, 1, "建筑物属性", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(2, 2, 1, 1, "年平均雷暴日Td(d/a)", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(3, 3, 1, 1, "年平均密度Ng(次/(km2.a))", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(4, 4, 1, 1, "预计雷击次数N(次/a)", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(5, 5, 1, 1, "防雷类别", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 2, 2, this.m_CalculateData.Ae.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(1, 1, 2, 2, this.m_CalculateData.BuildingParamter, CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(2, 2, 2, 2, this.m_CalculateData.Td.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(3, 3, 2, 2, this.m_CalculateData.Ng.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(4, 4, 2, 2, this.m_CalculateData.N.ToString(), CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(5, 5, 2, 2, this.m_CalculateData.ProtectionCategory, CellInfo.CellInfoType.CIT_Text));
			return list;
		}

		private CalculationData m_CalculateData;
	}
}
